package com.neu.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;

import com.neu.pojo.Model;
import com.neu.pojo.Worker;
import com.neu.table.ModelShowTable;
import com.neu.table.ModelTable;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JTable;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CheckModel extends JFrame {

	private JPanel contentPane;
	private JTable table;
	private ModelShowTable modelShowTable;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CheckModel frame = new CheckModel(new Worker(),new Model());
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CheckModel(Worker w,Model m) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 640, 466);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("ID:"+m.getId()+" 模板名字:"+m.getName());
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
		lblNewLabel.setBounds(37, 45, 337, 40);
		contentPane.add(lblNewLabel);
		
		JButton btnNewButton = new JButton("添加");
		btnNewButton.setBounds(439, 47, 132, 40);
		contentPane.add(btnNewButton);
		btnNewButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				AddProblemUI addProblemUI = new AddProblemUI(w,m);
				addProblemUI.setVisible(true);
				setVisible(false);
			}
		});
		
		this.modelShowTable = new ModelShowTable(m);//
		table = new JTable(this.modelShowTable);//用模式做表格
		table.setBounds(37, 125, 556, 226);
		contentPane.add(table);
		
		JButton btnNewButton_1 = new JButton("删除");
		btnNewButton_1.setBounds(169, 385, 97, 23);
		contentPane.add(btnNewButton_1);
		btnNewButton_1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				modelShowTable.delete(m);//删除表中某行
				
				modelShowTable.fireTableDataChanged();
				JOptionPane.showMessageDialog(null, "删除成功");//提示
			}
		});
		
		JButton btnNewButton_1_1 = new JButton("返回");
		btnNewButton_1_1.setBounds(349, 385, 97, 23);
		contentPane.add(btnNewButton_1_1);
		btnNewButton_1_1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				ModelUI modelUI = new ModelUI(w);//跳转新窗口
				modelUI.setVisible(true);
				setVisible(false);
			}
		});
		
		
		//窗口居中
		setLocationRelativeTo(null);
		
		//加滚动条
		JScrollPane jp = new JScrollPane(table);
		jp.setBounds(37, 125, 556, 226);
		contentPane.add(jp);
	}
}
